<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":-1,"unescape":false,"preload":true},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"./public/search.xml"};
  </script>

  <meta name="description" content="原文连接 JSON简介JSON: JavaScript Object Notation(JavaScript 对象表示法) JSON 是存储和交换文本信息的语法。类似 XML。 JSON 比 XML 更小、更快，更易解析。 SON 文本格式在语法上与创建 JavaScript 对象的代码相同。 由于这种相似性，无需解析器，JavaScript 程序能够使用内建的 eval() 函数，用 JSON">
<meta property="og:type" content="article">
<meta property="og:title" content="JSON简介">
<meta property="og:url" content="http://yoursite.com/2020/07/12/JSON%E7%AE%80%E4%BB%8B/index.html">
<meta property="og:site_name" content="GipBaby270&#39;s Blog">
<meta property="og:description" content="原文连接 JSON简介JSON: JavaScript Object Notation(JavaScript 对象表示法) JSON 是存储和交换文本信息的语法。类似 XML。 JSON 比 XML 更小、更快，更易解析。 SON 文本格式在语法上与创建 JavaScript 对象的代码相同。 由于这种相似性，无需解析器，JavaScript 程序能够使用内建的 eval() 函数，用 JSON">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-07-12T12:18:09.944Z">
<meta property="article:modified_time" content="2020-07-12T12:19:30.114Z">
<meta property="article:author" content="Gip886">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="http://yoursite.com/2020/07/12/JSON%E7%AE%80%E4%BB%8B/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>JSON简介 | GipBaby270's Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    
    <a href="https://github.com/Gip886" target="_blank" rel="noopener" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#64CEAA; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
    
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">GipBaby270's Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Fighting for BAT!</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2020/07/12/JSON%E7%AE%80%E4%BB%8B/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/%E5%A4%B4%E5%83%8F.jpg">
      <meta itemprop="name" content="Gip886">
      <meta itemprop="description" content="为了更美好的明天而战">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="GipBaby270's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          JSON简介
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2020-07-12 20:18:09 / 修改时间：20:19:30" itemprop="dateCreated datePublished" datetime="2020-07-12T20:18:09+08:00">2020-07-12</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/JS%E5%9F%BA%E7%A1%80/" itemprop="url" rel="index"><span itemprop="name">JS基础</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>7.9k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>7 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p><a href="https://www.runoob.com/json/json-tutorial.html" target="_blank" rel="noopener">原文连接</a></p>
<h1 id="JSON简介"><a href="#JSON简介" class="headerlink" title="JSON简介"></a>JSON简介</h1><p>JSON: <strong>J</strong>ava<strong>S</strong>cript <strong>O</strong>bject <strong>N</strong>otation(JavaScript 对象表示法)</p>
<p>JSON 是存储和交换文本信息的语法。类似 XML。</p>
<p>JSON 比 XML 更小、更快，更易解析。</p>
<p>SON 文本格式在语法上与创建 JavaScript 对象的代码相同。</p>
<p>由于这种相似性，无需解析器，JavaScript 程序能够使用内建的 eval() 函数，用 JSON 数据来生成原生的 JavaScript 对象。</p>
<a id="more"></a>

<h2 id="与-XML-相同之处"><a href="#与-XML-相同之处" class="headerlink" title="与 XML 相同之处"></a>与 XML 相同之处</h2><ul>
<li>JSON 是纯文本</li>
<li>JSON 具有”自我描述性”（人类可读）</li>
<li>JSON 具有层级结构（值中存在值）</li>
<li>JSON 可通过 JavaScript 进行解析</li>
<li>JSON 数据可使用 AJAX 进行传输</li>
</ul>
<h2 id="与-XML-不同之处"><a href="#与-XML-不同之处" class="headerlink" title="与 XML 不同之处"></a>与 XML 不同之处</h2><ul>
<li>没有结束标签</li>
<li>更短</li>
<li>读写的速度更快</li>
<li>能够使用内建的 JavaScript eval() 方法进行解析</li>
<li>使用数组</li>
<li>不使用保留字</li>
</ul>
<h2 id="为什么使用-JSON？"><a href="#为什么使用-JSON？" class="headerlink" title="为什么使用 JSON？"></a>为什么使用 JSON？</h2><p>对于 AJAX 应用程序来说，JSON 比 XML 更快更易使用：</p>
<h4 id="使用-XML"><a href="#使用-XML" class="headerlink" title="使用 XML"></a>使用 XML</h4><ul>
<li>读取 XML 文档</li>
<li>使用 XML DOM 来循环遍历文档</li>
<li>读取值并存储在变量中</li>
</ul>
<h4 id="使用-JSON"><a href="#使用-JSON" class="headerlink" title="使用 JSON"></a>使用 JSON</h4><ul>
<li>读取 JSON 字符串</li>
<li>用 eval() 处理 JSON 字符串</li>
</ul>
<h1 id="JSON-语法"><a href="#JSON-语法" class="headerlink" title="JSON 语法"></a>JSON 语法</h1><p>JSON 语法是 JavaScript 对象表示语法的子集。</p>
<ul>
<li>数据在名称/值对中</li>
<li>数据由逗号分隔</li>
<li>大括号保存对象</li>
<li>中括号保存数组</li>
</ul>
<h2 id="JSON-名称-值对"><a href="#JSON-名称-值对" class="headerlink" title="JSON 名称/值对"></a>JSON 名称/值对</h2><p>JSON 数据的书写格式是：名称/值对。</p>
<p>名称/值对包括字段名称（在双引号中），后面写一个冒号，然后是值：</p>
<p>“name” : “菜鸟教程”</p>
<p>这很容易理解，等价于这条 JavaScript 语句：</p>
<p>name = “菜鸟教程”</p>
<h2 id="JSON-值"><a href="#JSON-值" class="headerlink" title="JSON 值"></a>JSON 值</h2><p>JSON 值可以是：</p>
<ul>
<li>数字（整数或浮点数）</li>
<li>字符串（在双引号中）</li>
<li>逻辑值（true 或 false）</li>
<li>数组（在中括号中）</li>
<li>对象（在大括号中）</li>
<li>null</li>
</ul>
<h2 id="JSON-数字"><a href="#JSON-数字" class="headerlink" title="JSON 数字"></a>JSON 数字</h2><p>JSON 数字可以是整型或者浮点型：</p>
<p><code>{ &quot;age&quot;:30 }</code></p>
<h2 id="JSON-对象"><a href="#JSON-对象" class="headerlink" title="JSON 对象"></a>JSON 对象</h2><p>JSON 对象在大括号（{}）中书写：</p>
<p>对象可以包含多个名称/值对：</p>
<p><code>{ &quot;name&quot;:&quot;菜鸟教程&quot; , &quot;url&quot;:&quot;www.runoob.com&quot; }</code></p>
<p>这一点也容易理解，与这条 JavaScript 语句等价：</p>
<p>name = “菜鸟教程” url = “<a href="http://www.runoob.com&quot;" target="_blank" rel="noopener">www.runoob.com&quot;</a></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">name &#x3D; &quot;菜鸟教程&quot;</span><br><span class="line">url &#x3D; &quot;www.runoob.com&quot;</span><br></pre></td></tr></table></figure>

<h2 id="JSON-数组"><a href="#JSON-数组" class="headerlink" title="JSON 数组"></a>JSON 数组</h2><p>JSON 数组在中括号中书写：</p>
<p>数组可包含多个对象：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">&quot;sites&quot;: [</span><br><span class="line">&#123; &quot;name&quot;:&quot;菜鸟教程&quot; , &quot;url&quot;:&quot;www.runoob.com&quot; &#125;, </span><br><span class="line">&#123; &quot;name&quot;:&quot;google&quot; , &quot;url&quot;:&quot;www.google.com&quot; &#125;, </span><br><span class="line">&#123; &quot;name&quot;:&quot;微博&quot; , &quot;url&quot;:&quot;www.weibo.com&quot; &#125;</span><br><span class="line">]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<p>在上面的例子中，对象 “sites” 是包含三个对象的数组。每个对象代表一条关于某个网站（name、url）的记录。</p>
<h2 id="JSON-布尔值"><a href="#JSON-布尔值" class="headerlink" title="JSON 布尔值"></a>JSON 布尔值</h2><p>JSON 布尔值可以是 true 或者 false：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123; &quot;flag&quot;:true &#125;</span><br></pre></td></tr></table></figure>

<h2 id="JSON-null"><a href="#JSON-null" class="headerlink" title="JSON null"></a>JSON null</h2><p>JSON 可以设置 null 值：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123; &quot;runoob&quot;:null &#125;</span><br></pre></td></tr></table></figure>

<h2 id="JSON-使用-JavaScript-语法"><a href="#JSON-使用-JavaScript-语法" class="headerlink" title="JSON 使用 JavaScript 语法"></a>JSON 使用 JavaScript 语法</h2><p>因为 JSON 使用 JavaScript 语法，所以无需额外的软件就能处理 JavaScript 中的 JSON。</p>
<p>通过 JavaScript，您可以创建一个对象数组，并像这样进行赋值：</p>
<h3 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">var sites &#x3D; [</span><br><span class="line">    &#123; &quot;name&quot;:&quot;runoob&quot; , &quot;url&quot;:&quot;www.runoob.com&quot; &#125;, </span><br><span class="line">    &#123; &quot;name&quot;:&quot;google&quot; , &quot;url&quot;:&quot;www.google.com&quot; &#125;, </span><br><span class="line">    &#123; &quot;name&quot;:&quot;微博&quot; , &quot;url&quot;:&quot;www.weibo.com&quot; &#125;</span><br><span class="line">];</span><br></pre></td></tr></table></figure>

<p>可以像这样访问 JavaScript 对象数组中的第一项（索引从 0 开始）：</p>
<p><code>sites[0].name;</code></p>
<p>返回的内容是：</p>
<p><strong>runoob</strong></p>
<p>可以像这样修改数据：</p>
<p><code>sites[0].name=&quot;菜鸟教程&quot;;</code></p>
<h2 id="JSON-文件"><a href="#JSON-文件" class="headerlink" title="JSON 文件"></a>JSON 文件</h2><ul>
<li>JSON 文件的文件类型是 “.json”</li>
<li>JSON 文本的 MIME 类型是 “application/json”</li>
</ul>
<h1 id="JSON-vs-XML"><a href="#JSON-vs-XML" class="headerlink" title="JSON vs XML"></a>JSON vs XML</h1><p>JSON 和 XML 都用于接收 web 服务端的数据。</p>
<p>JSON 和 XML在写法上有所不同，如下所示：</p>
<h2 id="JSON-实例"><a href="#JSON-实例" class="headerlink" title="JSON 实例"></a>JSON 实例</h2><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">    <span class="attr">"sites"</span>: [</span><br><span class="line">    &#123; <span class="attr">"name"</span>:<span class="string">"菜鸟教程"</span> , <span class="attr">"url"</span>:<span class="string">"www.runoob.com"</span> &#125;, </span><br><span class="line">    &#123; <span class="attr">"name"</span>:<span class="string">"google"</span> , <span class="attr">"url"</span>:<span class="string">"www.google.com"</span> &#125;, </span><br><span class="line">    &#123; <span class="attr">"name"</span>:<span class="string">"微博"</span> , <span class="attr">"url"</span>:<span class="string">"www.weibo.com"</span> &#125;</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="XML-实例"><a href="#XML-实例" class="headerlink" title="XML 实例"></a>XML 实例</h2><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">sites</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">site</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">name</span>&gt;</span>菜鸟教程<span class="tag">&lt;/<span class="name">name</span>&gt;</span> <span class="tag">&lt;<span class="name">url</span>&gt;</span>www.runoob.com<span class="tag">&lt;/<span class="name">url</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">site</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">site</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">name</span>&gt;</span>google<span class="tag">&lt;/<span class="name">name</span>&gt;</span> <span class="tag">&lt;<span class="name">url</span>&gt;</span>www.google.com<span class="tag">&lt;/<span class="name">url</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">site</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">site</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">name</span>&gt;</span>微博<span class="tag">&lt;/<span class="name">name</span>&gt;</span> <span class="tag">&lt;<span class="name">url</span>&gt;</span>www.weibo.com<span class="tag">&lt;/<span class="name">url</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">site</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">sites</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h2 id="最大的不同"><a href="#最大的不同" class="headerlink" title="最大的不同"></a>最大的不同</h2><p><strong>XML 需要使用 XML 解析器来解析，JSON 可以使用标准的 JavaScript 函数来解析。</strong></p>
<ul>
<li><a href="https://www.runoob.com/js/javascript-json-parse.html" target="_blank" rel="noopener">JSON.parse()</a>: 将一个 JSON 字符串转换为 JavaScript 对象。</li>
<li><a href="https://www.runoob.com/js/javascript-json-stringify.html" target="_blank" rel="noopener">JSON.stringify()</a>: 于将 JavaScript 值转换为 JSON 字符串。</li>
</ul>
<h2 id="为什么-JSON-比-XML-更好？"><a href="#为什么-JSON-比-XML-更好？" class="headerlink" title="为什么 JSON 比 XML 更好？"></a>为什么 JSON 比 XML 更好？</h2><p>XML 比 JSON 更难解析。</p>
<p>JSON 可以直接使用现有的 JavaScript 对象解析。</p>
<p>针对 AJAX 应用，JSON 比 XML 数据加载更快，而且更简单：</p>
<p>使用 XML</p>
<ul>
<li>获取 XML 文档</li>
<li>使用 XML DOM 迭代循环文档</li>
<li>接数据解析出来复制给变量</li>
</ul>
<p>使用 JSON</p>
<ul>
<li>获取 JSON 字符串</li>
<li>JSON.Parse 解析 JSON 字符串</li>
</ul>
<h1 id="JSON-对象-1"><a href="#JSON-对象-1" class="headerlink" title="JSON 对象"></a>JSON 对象</h1><h2 id="对象语法"><a href="#对象语法" class="headerlink" title="对象语法"></a>对象语法</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123; &quot;name&quot;:&quot;runoob&quot;, &quot;alexa&quot;:10000, &quot;site&quot;:null &#125;</span><br></pre></td></tr></table></figure>

<p>JSON 对象使用在大括号({})中书写。</p>
<p>对象可以包含多个 <strong>key/value（键/值）</strong>对。</p>
<p><strong>key 必须是字符串，value 可以是合法的 JSON 数据类型（字符串, 数字, 对象, 数组, 布尔值或 null）。</strong></p>
<p>key 和 value 中使用冒号<strong>(:)</strong>分割。</p>
<p>每个 key/value 对使用逗号<strong>(,)</strong>分割。</p>
<h2 id="访问对象值"><a href="#访问对象值" class="headerlink" title="访问对象值"></a>访问对象值</h2><p>你可以使用点号（.）来访问对象的值：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">var myObj, x;</span><br><span class="line">myObj &#x3D; &#123; &quot;name&quot;:&quot;runoob&quot;, &quot;alexa&quot;:10000, &quot;site&quot;:null &#125;;</span><br><span class="line">x &#x3D; myObj.name;</span><br></pre></td></tr></table></figure>

<p>你也可以使用中括号（[]）来访问对象的值：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">var myObj, x;</span><br><span class="line">myObj &#x3D; &#123; &quot;name&quot;:&quot;runoob&quot;, &quot;alexa&quot;:10000, &quot;site&quot;:null &#125;;</span><br><span class="line">x &#x3D; myObj[&quot;name&quot;];</span><br></pre></td></tr></table></figure>

<h2 id="循环对象"><a href="#循环对象" class="headerlink" title="循环对象"></a>循环对象</h2><p>你可以使用 for-in 来循环对象的<strong>属性</strong>：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">var myObj &#x3D; &#123; &quot;name&quot;:&quot;runoob&quot;, &quot;alexa&quot;:10000, &quot;site&quot;:null &#125;;</span><br><span class="line">for (x in myObj) &#123;</span><br><span class="line">    document.getElementById(&quot;demo&quot;).innerHTML +&#x3D; x + &quot;&lt;br&gt;&quot;;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>使用 for-in 来循环对象的属性:</p>
<p>name<br>alexa<br>site</p>
<p>在 for-in 循环对象的属性时，使用中括号（[]）来访问<strong>属性的值</strong>：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">var myObj &#x3D; &#123; &quot;name&quot;:&quot;runoob&quot;, &quot;alexa&quot;:10000, &quot;site&quot;:null &#125;;</span><br><span class="line">for (x in myObj) &#123;</span><br><span class="line">    document.getElementById(&quot;demo&quot;).innerHTML +&#x3D; myObj[x] + &quot;&lt;br&gt;&quot;;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>在 for-in 循环对象的属性时，使用中括号（[]）来访问属性的值：</p>
<p>runoob<br>10000<br>null</p>
<h2 id="嵌套-JSON-对象"><a href="#嵌套-JSON-对象" class="headerlink" title="嵌套 JSON 对象"></a>嵌套 JSON 对象</h2><p>JSON 对象中可以包含另外一个 JSON 对象：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">myObj &#x3D; &#123;</span><br><span class="line">    &quot;name&quot;:&quot;runoob&quot;,</span><br><span class="line">    &quot;alexa&quot;:10000,</span><br><span class="line">    &quot;sites&quot;: &#123;</span><br><span class="line">        &quot;site1&quot;:&quot;www.runoob.com&quot;,</span><br><span class="line">        &quot;site2&quot;:&quot;m.runoob.com&quot;,</span><br><span class="line">        &quot;site3&quot;:&quot;c.runoob.com&quot;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>你可以使用点号(.)或者中括号([])来访问嵌套的 JSON 对象。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">x &#x3D; myObj.sites.site1;</span><br><span class="line">&#x2F;&#x2F; 或者</span><br><span class="line">x &#x3D; myObj.sites[&quot;site1&quot;];</span><br></pre></td></tr></table></figure>

<h2 id="修改值"><a href="#修改值" class="headerlink" title="修改值"></a>修改值</h2><p>你可以使用点号(.)来修改 JSON 对象的值：</p>
<p><code>myObj.sites.site1 = &quot;www.google.com&quot;;</code></p>
<p><code>myObj.sites[&quot;site1&quot;] = &quot;www.google.com&quot;;</code></p>
<h2 id="删除对象属性"><a href="#删除对象属性" class="headerlink" title="删除对象属性"></a>删除对象属性</h2><p>我们可以使用 <strong>delete</strong> 关键字来删除 JSON 对象的属性：</p>
<p><code>delete myObj.sites.site1;</code></p>
<p><code>delete myObj.sites[&quot;site1&quot;]</code></p>
<h1 id="JSON-数组-1"><a href="#JSON-数组-1" class="headerlink" title="JSON 数组"></a>JSON 数组</h1><h2 id="数组作为-JSON-对象"><a href="#数组作为-JSON-对象" class="headerlink" title="数组作为 JSON 对象"></a>数组作为 JSON 对象</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[ &quot;Google&quot;, &quot;Runoob&quot;, &quot;Taobao&quot; ]</span><br></pre></td></tr></table></figure>

<p>JSON 数组在中括号中书写。</p>
<p>JSON 中数组值必须是合法的 JSON 数据类型（字符串, 数字, 对象, 数组, 布尔值或 null）。</p>
<p>JavaScript 中，数组值可以是以上的 JSON 数据类型，也可以是 JavaScript 的表达式，包括函数，日期，及 <em>undefined</em>。</p>
<h2 id="JSON-对象中的数组"><a href="#JSON-对象中的数组" class="headerlink" title="JSON 对象中的数组"></a>JSON 对象中的数组</h2><p>对象属性的值可以是一个数组：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">&quot;name&quot;:&quot;网站&quot;,</span><br><span class="line">&quot;num&quot;:3,</span><br><span class="line">&quot;sites&quot;:[ &quot;Google&quot;, &quot;Runoob&quot;, &quot;Taobao&quot; ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>我们可以使用索引值来访问数组：</p>
<p><code>x = myObj.sites[0];</code></p>
<h2 id="循环数组"><a href="#循环数组" class="headerlink" title="循环数组"></a>循环数组</h2><p>你可以使用 for-in 来访问数组：</p>
<p><code>for (i in myObj.sites) {    x += myObj.sites[i] + &quot;&lt;br&gt;&quot;; }</code></p>
<p>你也可以使用 for 循环：</p>
<p><code>for (i = 0; i &lt; myObj.sites.length; i++) {    x += myObj.sites[i] + &quot;&lt;br&gt;&quot;; }</code></p>
<h2 id="嵌套-JSON-对象中的数组"><a href="#嵌套-JSON-对象中的数组" class="headerlink" title="嵌套 JSON 对象中的数组"></a>嵌套 JSON 对象中的数组</h2><p>JSON 对象中数组可以包含另外一个数组，或者另外一个 JSON 对象：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">myObj &#x3D; &#123;</span><br><span class="line">    &quot;name&quot;:&quot;网站&quot;,</span><br><span class="line">    &quot;num&quot;:3,</span><br><span class="line">    &quot;sites&quot;: [</span><br><span class="line">        &#123; &quot;name&quot;:&quot;Google&quot;, &quot;info&quot;:[ &quot;Android&quot;, &quot;Google 搜索&quot;, &quot;Google 翻译&quot; ] &#125;,</span><br><span class="line">        &#123; &quot;name&quot;:&quot;Runoob&quot;, &quot;info&quot;:[ &quot;菜鸟教程&quot;, &quot;菜鸟工具&quot;, &quot;菜鸟微信&quot; ] &#125;,</span><br><span class="line">        &#123; &quot;name&quot;:&quot;Taobao&quot;, &quot;info&quot;:[ &quot;淘宝&quot;, &quot;网购&quot; ] &#125;</span><br><span class="line">    ]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>我们可以使用 for-in 来循环访问每个数组：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">for (i in myObj.sites) &#123;</span><br><span class="line">    x +&#x3D; &quot;&lt;h1&gt;&quot; + myObj.sites[i].name + &quot;&lt;&#x2F;h1&gt;&quot;;</span><br><span class="line">    for (j in myObj.sites[i].info) &#123;</span><br><span class="line">        x +&#x3D; myObj.sites[i].info[j] + &quot;&lt;br&gt;&quot;;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="修改数组值"><a href="#修改数组值" class="headerlink" title="修改数组值"></a>修改数组值</h2><p>你可以使用索引值来修改数组值：</p>
<p><code>myObj.sites[1] = &quot;Github&quot;;</code></p>
<h2 id="删除数组元素"><a href="#删除数组元素" class="headerlink" title="删除数组元素"></a>删除数组元素</h2><p><code>delete myObj.sites[1];</code></p>
<h1 id="JSON-parse"><a href="#JSON-parse" class="headerlink" title="JSON.parse()"></a>JSON.parse()</h1><p>JSON 通常用于与服务端交换数据。</p>
<p>在接收服务器数据时一般是字符串。</p>
<p>我们可以使用 JSON.parse() 方法将数据转换为 JavaScript 对象。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">JSON.parse(text[, reviver])</span><br></pre></td></tr></table></figure>

<p><strong>参数说明：</strong></p>
<ul>
<li><strong>text:</strong>必需， 一个有效的 JSON 字符串。</li>
<li><strong>reviver:</strong> 可选，一个转换结果的函数， 将为对象的每个成员调用此函数。</li>
</ul>
<h2 id="JSON-解析实例"><a href="#JSON-解析实例" class="headerlink" title="JSON 解析实例"></a>JSON 解析实例</h2><p>例如我们从服务器接收了以下数据：</p>
<p><code>{ &quot;name&quot;:&quot;runoob&quot;, &quot;alexa&quot;:10000, &quot;site&quot;:&quot;www.runoob.com&quot; }</code></p>
<p>我们使用 JSON.parse() 方法处理以上数据，将其转换为 JavaScript 对象：</p>
<p><code>var obj = JSON.parse(&#39;{ &quot;name&quot;:&quot;runoob&quot;, &quot;alexa&quot;:10000, &quot;site&quot;:&quot;www.runoob.com&quot; }&#39;);</code></p>
<h2 id="jQuery-使用-JSONP"><a href="#jQuery-使用-JSONP" class="headerlink" title="jQuery 使用 JSONP"></a>jQuery 使用 JSONP</h2><p>以上代码可以使用 jQuery 代码实例：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">    &lt;meta charset&#x3D;&quot;utf-8&quot;&gt;</span><br><span class="line">    &lt;title&gt;JSONP 实例&lt;&#x2F;title&gt;</span><br><span class="line">    &lt;script src&#x3D;&quot;https:&#x2F;&#x2F;cdn.static.runoob.com&#x2F;libs&#x2F;jquery&#x2F;1.8.3&#x2F;jquery.js&quot;&gt;&lt;&#x2F;script&gt;    </span><br><span class="line">&lt;&#x2F;head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">&lt;div id&#x3D;&quot;divCustomers&quot;&gt;&lt;&#x2F;div&gt;</span><br><span class="line">&lt;script&gt;</span><br><span class="line">$.getJSON(&quot;https:&#x2F;&#x2F;www.runoob.com&#x2F;try&#x2F;ajax&#x2F;jsonp.php?jsoncallback&#x3D;?&quot;, function(data) &#123;</span><br><span class="line">    </span><br><span class="line">    var html &#x3D; &#39;&lt;ul&gt;&#39;;</span><br><span class="line">    for(var i &#x3D; 0; i &lt; data.length; i++)</span><br><span class="line">    &#123;</span><br><span class="line">        html +&#x3D; &#39;&lt;li&gt;&#39; + data[i] + &#39;&lt;&#x2F;li&gt;&#39;;</span><br><span class="line">    &#125;</span><br><span class="line">    html +&#x3D; &#39;&lt;&#x2F;ul&gt;&#39;;</span><br><span class="line">    </span><br><span class="line">    $(&#39;#divCustomers&#39;).html(html); </span><br><span class="line">&#125;);</span><br><span class="line">&lt;&#x2F;script&gt;</span><br><span class="line">&lt;&#x2F;body&gt;</span><br><span class="line">&lt;&#x2F;html&gt;</span><br></pre></td></tr></table></figure>

<h1 id="JSON-stringify"><a href="#JSON-stringify" class="headerlink" title="JSON.stringify()"></a>JSON.stringify()</h1><p>JSON 通常用于与服务端交换数据。</p>
<p>在向服务器发送数据时一般是字符串。</p>
<p>我们可以使用 JSON.stringify() 方法将 JavaScript 对象转换为字符串。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">JSON.stringify(value[, replacer[, space]])</span><br></pre></td></tr></table></figure>

<p><strong>参数说明：</strong></p>
<ul>
<li><p>value:</p>
<p>必需， 要转换的 JavaScript 值（通常为对象或数组）。</p>
</li>
<li><p>replacer:</p>
<p>可选。用于转换结果的函数或数组。</p>
<p>如果 replacer 为函数，则 JSON.stringify 将调用该函数，并传入每个成员的键和值。使用返回值而不是原始值。如果此函数返回 undefined，则排除成员。根对象的键是一个空字符串：””。</p>
<p>如果 replacer 是一个数组，则仅转换该数组中具有键值的成员。成员的转换顺序与键在数组中的顺序一样。当 value 参数也为数组时，将忽略 replacer 数组。</p>
</li>
<li><p>space:</p>
<p>可选，文本添加缩进、空格和换行符，如果 space 是一个数字，则返回值文本在每个级别缩进指定数目的空格，如果 space 大于 10，则文本缩进 10 个空格。space 也可以使用非数字，如：\t。</p>
</li>
</ul>

    </div>

    
    
    
        <div class="reward-container">
  <div>坚持原创技术分享，您的支持将鼓励我继续分享！</div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/wechatpay.png" alt="Gip886 微信支付">
        <p>微信支付</p>
      </div>

  </div>
</div>


      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2020/07/11/%E5%AD%A6%E4%B9%A0Git%E7%9A%84%E4%BD%BF%E7%94%A8/" rel="prev" title="学习Git的使用">
      <i class="fa fa-chevron-left"></i> 学习Git的使用
    </a></div>
      <div class="post-nav-item">
    <a href="/2020/07/13/AJAX%20%E7%AE%80%E4%BB%8B/" rel="next" title="AJAX 简介">
      AJAX 简介 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#JSON简介"><span class="nav-number">1.</span> <span class="nav-text">JSON简介</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#与-XML-相同之处"><span class="nav-number">1.1.</span> <span class="nav-text">与 XML 相同之处</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#与-XML-不同之处"><span class="nav-number">1.2.</span> <span class="nav-text">与 XML 不同之处</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#为什么使用-JSON？"><span class="nav-number">1.3.</span> <span class="nav-text">为什么使用 JSON？</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#使用-XML"><span class="nav-number">1.3.0.1.</span> <span class="nav-text">使用 XML</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#使用-JSON"><span class="nav-number">1.3.0.2.</span> <span class="nav-text">使用 JSON</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#JSON-语法"><span class="nav-number">2.</span> <span class="nav-text">JSON 语法</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#JSON-名称-值对"><span class="nav-number">2.1.</span> <span class="nav-text">JSON 名称&#x2F;值对</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JSON-值"><span class="nav-number">2.2.</span> <span class="nav-text">JSON 值</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JSON-数字"><span class="nav-number">2.3.</span> <span class="nav-text">JSON 数字</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JSON-对象"><span class="nav-number">2.4.</span> <span class="nav-text">JSON 对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JSON-数组"><span class="nav-number">2.5.</span> <span class="nav-text">JSON 数组</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JSON-布尔值"><span class="nav-number">2.6.</span> <span class="nav-text">JSON 布尔值</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JSON-null"><span class="nav-number">2.7.</span> <span class="nav-text">JSON null</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JSON-使用-JavaScript-语法"><span class="nav-number">2.8.</span> <span class="nav-text">JSON 使用 JavaScript 语法</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#实例"><span class="nav-number">2.8.1.</span> <span class="nav-text">实例</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JSON-文件"><span class="nav-number">2.9.</span> <span class="nav-text">JSON 文件</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#JSON-vs-XML"><span class="nav-number">3.</span> <span class="nav-text">JSON vs XML</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#JSON-实例"><span class="nav-number">3.1.</span> <span class="nav-text">JSON 实例</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#XML-实例"><span class="nav-number">3.2.</span> <span class="nav-text">XML 实例</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#最大的不同"><span class="nav-number">3.3.</span> <span class="nav-text">最大的不同</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#为什么-JSON-比-XML-更好？"><span class="nav-number">3.4.</span> <span class="nav-text">为什么 JSON 比 XML 更好？</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#JSON-对象-1"><span class="nav-number">4.</span> <span class="nav-text">JSON 对象</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#对象语法"><span class="nav-number">4.1.</span> <span class="nav-text">对象语法</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#访问对象值"><span class="nav-number">4.2.</span> <span class="nav-text">访问对象值</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#循环对象"><span class="nav-number">4.3.</span> <span class="nav-text">循环对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#嵌套-JSON-对象"><span class="nav-number">4.4.</span> <span class="nav-text">嵌套 JSON 对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#修改值"><span class="nav-number">4.5.</span> <span class="nav-text">修改值</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#删除对象属性"><span class="nav-number">4.6.</span> <span class="nav-text">删除对象属性</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#JSON-数组-1"><span class="nav-number">5.</span> <span class="nav-text">JSON 数组</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#数组作为-JSON-对象"><span class="nav-number">5.1.</span> <span class="nav-text">数组作为 JSON 对象</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#JSON-对象中的数组"><span class="nav-number">5.2.</span> <span class="nav-text">JSON 对象中的数组</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#循环数组"><span class="nav-number">5.3.</span> <span class="nav-text">循环数组</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#嵌套-JSON-对象中的数组"><span class="nav-number">5.4.</span> <span class="nav-text">嵌套 JSON 对象中的数组</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#修改数组值"><span class="nav-number">5.5.</span> <span class="nav-text">修改数组值</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#删除数组元素"><span class="nav-number">5.6.</span> <span class="nav-text">删除数组元素</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#JSON-parse"><span class="nav-number">6.</span> <span class="nav-text">JSON.parse()</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#JSON-解析实例"><span class="nav-number">6.1.</span> <span class="nav-text">JSON 解析实例</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#jQuery-使用-JSONP"><span class="nav-number">6.2.</span> <span class="nav-text">jQuery 使用 JSONP</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#JSON-stringify"><span class="nav-number">7.</span> <span class="nav-text">JSON.stringify()</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Gip886"
      src="/images/%E5%A4%B4%E5%83%8F.jpg">
  <p class="site-author-name" itemprop="name">Gip886</p>
  <div class="site-description" itemprop="description">为了更美好的明天而战</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">29</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/Gip886" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;Gip886" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>



      </div>
        <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=300 height=86 src="//music.163.com/outchain/player?type=2&id=492390949&auto=1&height=66"></iframe>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Gip886</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">153k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">2:19</span>
</div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script size="300" alpha="0.6" zIndex="-1" src="/lib/canvas-ribbon/canvas-ribbon.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>


  <script defer src="/lib/three/three.min.js"></script>
    <script defer src="/lib/three/canvas_lines.min.js"></script>


  




  
<script src="/js/local-search.js"></script>













  

  

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","model":{"jsonPath":"/live2dw/assets/koharu.model.json"},"display":{"position":"right","width":150,"height":300},"mobile":{"show":true},"log":false,"tagMode":false});</script></body>
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/clicklove.js"></script>
</html>

